package com.community.web.user.controller.complaint;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.community.common.login.LoginUserHolder;
import com.community.common.result.Result;
import com.community.model.entity.Complaint;
import com.community.web.user.service.ComplaintService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "报修模块")
@RestController
@RequestMapping("/user/complaint")
public class ComplaintController {
    @Autowired
    private ComplaintService service;

    @ApiOperation("添加报修事项")
    @PostMapping()
    public Result addComplaint(@RequestBody Complaint complaint){
        Long userId = LoginUserHolder.getLoginUser().getUserId();
        complaint.setUserId(userId.intValue());
        complaint.setComplaintStatus(0);
        service.save(complaint);
        return Result.ok();
    }

    @ApiOperation("根据用户id查询报修列表")
    @GetMapping()
    public Result<List<Complaint>> getList(){
        Long userId = LoginUserHolder.getLoginUser().getUserId();
        LambdaQueryWrapper<Complaint> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Complaint::getUserId, userId);
        List<Complaint> list = service.list(queryWrapper);
        return Result.ok(list);
    }

}
